package de.tc.stammdatenverwaltung.gui;

import de.tc.stammdatenverwaltung.functions.ExtensionFileFilter;
import de.tc.stammdatenverwaltung.functions.commonFunctions;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.TreeMap;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;

public class importDialog extends javax.swing.JDialog {

  private static int zeile = 0;

    public importDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        jTextField1.setText("");
        jTextField2.setText(";");

        setPreset(false);
        //die Reihenfolge, die Sascha braucht (zumindest jetzt)
    }

    private void setPreset(boolean fremd)
    {
      if (fremd)
      {
        jTextField3.setText("2");
        jTextField4.setText("4");
        jTextField5.setText("5");
        jTextField6.setText("3");
        jTextField7.setText("5");
        jTextField8.setText("6");
        jTextField9.setText("8");
        jTextField10.setText("11");
        jTextField11.setText("5");
        jTextField12.setText("10");
        jTextField13.setText("9");
        jTextField14.setText("5");
        jTextField15.setText("5");
        jTextField16.setText("5");
        jTextField17.setText("5");
        jTextField18.setText("5");
        jTextField19.setText("5");
        jTextField20.setText("5");
        jTextField21.setText("5");
        jTextField22.setText("5");
        jTextField23.setText("5");
        jTextField24.setText("5");
        jTextField25.setText("5");
        jTextField26.setText("5");
        jTextField27.setText("5");
        jTextField28.setText("5");
        jTextField29.setText("5");
        jTextField30.setText("5");
      }
      else
      {
        jTextField3.setText("2");
        jTextField4.setText("3");
        jTextField5.setText("4");
        jTextField6.setText("5");
        jTextField7.setText("6");
        jTextField8.setText("8");
        jTextField9.setText("9");
        jTextField10.setText("10");
        jTextField11.setText("11");
        jTextField12.setText("12");
        jTextField13.setText("13");
        jTextField14.setText("14");
        jTextField15.setText("7");
        jTextField16.setText("15");
        jTextField17.setText("16");
        jTextField18.setText("18");
        jTextField19.setText("19");
        jTextField20.setText("20");
        jTextField21.setText("21");
        jTextField22.setText("22");
        jTextField23.setText("23");
        jTextField24.setText("24");
        jTextField25.setText("17");
        jTextField26.setText("25");
        jTextField27.setText("26");
        jTextField28.setText("27");
        jTextField29.setText("28");
        jTextField30.setText("29");
      }
    }

    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jLabel3 = new javax.swing.JLabel();
    jTextField2 = new javax.swing.JTextField();
    jCheckBox1 = new javax.swing.JCheckBox();
    jPanel2 = new javax.swing.JPanel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jTextField3 = new javax.swing.JTextField();
    jTextField4 = new javax.swing.JTextField();
    jTextField5 = new javax.swing.JTextField();
    jTextField6 = new javax.swing.JTextField();
    jTextField7 = new javax.swing.JTextField();
    jLabel10 = new javax.swing.JLabel();
    jLabel11 = new javax.swing.JLabel();
    jLabel12 = new javax.swing.JLabel();
    jLabel13 = new javax.swing.JLabel();
    jLabel14 = new javax.swing.JLabel();
    jLabel15 = new javax.swing.JLabel();
    jLabel16 = new javax.swing.JLabel();
    jTextField8 = new javax.swing.JTextField();
    jTextField9 = new javax.swing.JTextField();
    jTextField10 = new javax.swing.JTextField();
    jTextField11 = new javax.swing.JTextField();
    jTextField12 = new javax.swing.JTextField();
    jTextField13 = new javax.swing.JTextField();
    jTextField14 = new javax.swing.JTextField();
    jLabel29 = new javax.swing.JLabel();
    jLabel17 = new javax.swing.JLabel();
    jLabel18 = new javax.swing.JLabel();
    jLabel20 = new javax.swing.JLabel();
    jLabel21 = new javax.swing.JLabel();
    jLabel22 = new javax.swing.JLabel();
    jLabel25 = new javax.swing.JLabel();
    jLabel26 = new javax.swing.JLabel();
    jLabel27 = new javax.swing.JLabel();
    jLabel28 = new javax.swing.JLabel();
    jTextField15 = new javax.swing.JTextField();
    jTextField16 = new javax.swing.JTextField();
    jTextField17 = new javax.swing.JTextField();
    jTextField18 = new javax.swing.JTextField();
    jTextField19 = new javax.swing.JTextField();
    jTextField20 = new javax.swing.JTextField();
    jTextField21 = new javax.swing.JTextField();
    jTextField22 = new javax.swing.JTextField();
    jTextField23 = new javax.swing.JTextField();
    jTextField24 = new javax.swing.JTextField();
    jLabel23 = new javax.swing.JLabel();
    jLabel30 = new javax.swing.JLabel();
    jLabel24 = new javax.swing.JLabel();
    jLabel31 = new javax.swing.JLabel();
    jLabel32 = new javax.swing.JLabel();
    jLabel33 = new javax.swing.JLabel();
    jTextField25 = new javax.swing.JTextField();
    jTextField26 = new javax.swing.JTextField();
    jTextField27 = new javax.swing.JTextField();
    jTextField28 = new javax.swing.JTextField();
    jTextField29 = new javax.swing.JTextField();
    jTextField30 = new javax.swing.JTextField();
    jButton2 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

    jLabel1.setFont(new java.awt.Font("Dialog", 1, 18));
    jLabel1.setText("Import von Kontakten ...");

    jLabel2.setText("Datei zum Import");

    jTextField1.setText("...");

    jButton1.setText("Datei wählen");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });

    jLabel3.setText("Spaltentrenner (einzelnes Zeichen!)");

    jTextField2.setText(";");

    jCheckBox1.setSelected(true);
    jCheckBox1.setText("enthält Spaltenköpfe");

    jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

    jLabel4.setFont(new java.awt.Font("Dialog", 1, 16));
    jLabel4.setText("Reihenfolge der Daten (Spaltennummer):");

    jLabel5.setText("Titel");

    jLabel6.setText("Vorname");

    jLabel7.setText("2. Name");

    jLabel8.setText("Name");

    jLabel9.setText("Spitzname");

    jTextField3.setText("jTextField3");

    jTextField4.setText("jTextField4");

    jTextField5.setText("jTextField5");

    jTextField6.setText("jTextField6");

    jTextField7.setText("jTextField7");

    jLabel10.setText("Anschrift");

    jLabel11.setText("PLZ / Ort");

    jLabel12.setText("Telefon");

    jLabel13.setText("Fax");

    jLabel14.setText("Mobil");

    jLabel15.setText("E-Mail 1");

    jLabel16.setText("E-Mail 2");

    jTextField8.setText("jTextField8");

    jTextField9.setText("jTextField9");

    jTextField10.setText("jTextField10");

    jTextField11.setText("jTextField11");

    jTextField12.setText("jTextField12");

    jTextField13.setText("jTextField13");

    jTextField14.setText("jTextField14");

    jLabel29.setText("Geburtstag");

    jLabel17.setText("Abitur");

    jLabel18.setText("Ämter");

    jLabel20.setText("Firma");

    jLabel21.setText("Position");

    jLabel22.setText("Beruf");

    jLabel25.setText("Fa. PLZ / Ort");

    jLabel26.setText("Fa. Telefon");

    jLabel27.setText("Fa. Fax");

    jLabel28.setText("Fa. E-Mail");

    jTextField15.setText("jTextField15");

    jTextField16.setText("jTextField16");

    jTextField17.setText("jTextField17");

    jTextField18.setText("jTextField18");

    jTextField19.setText("jTextField19");

    jTextField20.setText("jTextField20");

    jTextField21.setText("jTextField21");

    jTextField22.setText("jTextField22");

    jTextField23.setText("jTextField23");

    jTextField24.setText("jTextField24");

    jLabel23.setText("Anrede");

    jLabel30.setText("Tag");

    jLabel24.setText("Verein");

    jLabel31.setText("Hinzugefügt");

    jLabel32.setText("Fa. Anschrift");

    jLabel33.setText("Geändert");

    jTextField25.setText("jTextField25");

    jTextField26.setText("jTextField26");

    jTextField27.setText("jTextField27");

    jTextField28.setText("jTextField28");

    jTextField29.setText("jTextField29");

    jTextField30.setText("jTextField30");

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jLabel4)
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel12)
              .addComponent(jLabel14)
              .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(4, 4, 4))
                      .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(34, 34, 34)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                      .addComponent(jLabel7)
                      .addGap(19, 19, 19)))
                  .addGroup(jPanel2Layout.createSequentialGroup()
                    .addComponent(jLabel6)
                    .addGap(14, 14, 14)))
                .addGroup(jPanel2Layout.createSequentialGroup()
                  .addComponent(jLabel5)
                  .addGap(41, 41, 41)))
              .addComponent(jLabel13)
              .addComponent(jLabel11)
              .addComponent(jLabel10)
              .addComponent(jLabel15)
              .addComponent(jLabel16))
            .addGap(15, 15, 15)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
              .addComponent(jTextField14, javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jTextField13, javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jTextField8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
              .addComponent(jTextField9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
              .addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
              .addComponent(jTextField4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
              .addComponent(jTextField5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
              .addComponent(jTextField6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
              .addComponent(jTextField7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
              .addComponent(jTextField12, javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jTextField11)
              .addComponent(jTextField10, javax.swing.GroupLayout.Alignment.LEADING))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jLabel22)
                  .addComponent(jLabel21)
                  .addComponent(jLabel20)
                  .addComponent(jLabel25)
                  .addComponent(jLabel26)
                  .addComponent(jLabel27)
                  .addComponent(jLabel28))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                  .addComponent(jTextField18)
                  .addComponent(jTextField19)
                  .addComponent(jTextField20)
                  .addComponent(jTextField21)
                  .addComponent(jTextField22)
                  .addComponent(jTextField23)
                  .addComponent(jTextField24, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
              .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jLabel23)
                  .addComponent(jLabel24)
                  .addComponent(jLabel30)
                  .addComponent(jLabel32)
                  .addComponent(jLabel33)
                  .addComponent(jLabel31))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                  .addComponent(jTextField25)
                  .addComponent(jTextField26)
                  .addComponent(jTextField27)
                  .addComponent(jTextField28)
                  .addComponent(jTextField29)
                  .addComponent(jTextField30, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
        .addGap(107, 107, 107))
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jLabel29)
          .addComponent(jLabel18)
          .addComponent(jLabel17))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
          .addComponent(jTextField15, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
          .addComponent(jTextField16)
          .addComponent(jTextField17))
        .addContainerGap(296, Short.MAX_VALUE))
    );
    jPanel2Layout.setVerticalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addComponent(jLabel4)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel5)
              .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel6)
              .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel7)
              .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel8)
              .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel9)
              .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel10)
              .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel11)
              .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel20)
              .addComponent(jTextField18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel21)
              .addComponent(jTextField19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel22)
              .addComponent(jTextField20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel25)
              .addComponent(jTextField21, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel26)
              .addComponent(jTextField22, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel27)
              .addComponent(jTextField23, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel28)
              .addComponent(jTextField24, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel12)
              .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel13)
              .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel14)
              .addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel15)
              .addComponent(jTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel16)
              .addComponent(jTextField14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel29)
              .addComponent(jTextField15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel24)
              .addComponent(jTextField25, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel23)
              .addComponent(jTextField26, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel30)
              .addComponent(jTextField27, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel32)
              .addComponent(jTextField28, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel33)
              .addComponent(jTextField29, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel31)
              .addComponent(jTextField30, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel17)
          .addComponent(jTextField16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel18)
          .addComponent(jTextField17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    jButton2.setText("Import beginnen");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
          .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel2))
          .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jButton1))
          .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jCheckBox1)
              .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGap(116, 116, 116))
          .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)))
        .addContainerGap())
    );
    jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
        .addComponent(jLabel1)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jLabel2)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jButton1))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel3)
          .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jCheckBox1)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addComponent(jButton2)
        .addContainerGap())
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
      Color old = jButton2.getBackground();
      jButton2.setBackground(Color.red);
      startImport();
      jButton2.setBackground(old);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
      String home = System.getProperty("user.home");
      JFileChooser jf1 = new JFileChooser(new File(home));
      FileFilter ff1 = new ExtensionFileFilter("CSV", "csv");
      jf1.setFileFilter(ff1);
      jf1.setMultiSelectionEnabled(false);
      if (jf1.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
      { //Datei ausgewaehlt
        jTextField1.setText(jf1.getSelectedFile().getAbsolutePath());
      }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void startImport() 
    {
      File f = new File(jTextField1.getText());
      String separator = jTextField2.getText();
      if (f.isFile() && f.canRead()) //Verzeichnis und nicht lesbar ausschliessen
      {
        try
        {
          FileReader fr = new FileReader(f);
          BufferedReader buf = new BufferedReader(fr);

          String fileEncoding = fr.getEncoding();

          TreeMap <Integer, String> fieldOrder = createFieldOrder();

          boolean first = true;
          String line = null;
          
          while ( (line = buf.readLine()) != null)
          {
            if (first)
            {
              first = false;
              if (! jCheckBox1.isSelected())
                insertData(line.split(separator, -1), fieldOrder, fileEncoding); // negativ heißt: mach acuh leere elemente, das was wir wollen
            }
            else
              insertData(line.split(separator, -1), fieldOrder, fileEncoding);
          }
          JOptionPane.showMessageDialog(null, "Import erfolgreich; Importierte Zeilen: " + zeile,
                "Fehler!", JOptionPane.INFORMATION_MESSAGE);
        }
        catch (FileNotFoundException fne)
        {
          JOptionPane.showMessageDialog(null, "Die angegebene Datei existiert nicht (mehr)!\r\n" +
            fne.getLocalizedMessage(), "Fehler!", JOptionPane.ERROR_MESSAGE);
          fne.printStackTrace();
        }
        catch (UnsupportedEncodingException uee)
        {
          JOptionPane.showMessageDialog(null, "Die Datei hat einen nicht unterstützten Zeichensatz!\r\n" + 
            uee.getLocalizedMessage(), "Fehler!", JOptionPane.ERROR_MESSAGE);
          uee.printStackTrace();
        }
        catch (IOException ioe)
        {
          JOptionPane.showMessageDialog(null, "Vom angegebenen Ort kann nicht gelesen werden!\r\n" +
            ioe.getLocalizedMessage(), "Fehler!", JOptionPane.ERROR_MESSAGE);
          ioe.printStackTrace();
        }
        catch (ArrayIndexOutOfBoundsException aibo)
        {
          JOptionPane.showMessageDialog(null, 
            "Die Anzahl der Spalten stimmt nicht mit der Nummerierung überein, import abgebrochen." +
            commonFunctions.LS + "Erfolgreich importierte Zeilen: " + zeile,
            "Fehler!", JOptionPane.ERROR_MESSAGE);
          aibo.printStackTrace();
        }
        catch (SQLException sqle)
        {
          JOptionPane.showMessageDialog(null, "Konnte Kontakt nicht in die Datenbank einfügen!\r\n" +
              sqle.getLocalizedMessage(),
              "Fehler!", JOptionPane.ERROR_MESSAGE);
          sqle.printStackTrace();
        }
      }
      else
        JOptionPane.showMessageDialog(null, "Vom angegebenen Ort kann nicht gelesen werden!",
                "Fehler!", JOptionPane.ERROR_MESSAGE);
    }

    private TreeMap<Integer, String> createFieldOrder()
    {
      TreeMap<Integer, String> fieldOrder = new TreeMap<Integer, String>();
      try
      { //Treemap sortiert nach Keys - automatisch => seeehr komfortabel!
        fieldOrder.put(Integer.parseInt(jTextField3.getText()), "TITEL");
        fieldOrder.put(Integer.parseInt(jTextField4.getText()), "VNAME");
        fieldOrder.put(Integer.parseInt(jTextField5.getText()), "NAME2");
        fieldOrder.put(Integer.parseInt(jTextField6.getText()), "NNAME");
        fieldOrder.put(Integer.parseInt(jTextField7.getText()), "NICK");
        fieldOrder.put(Integer.parseInt(jTextField8.getText()), "ANSCHRIFT");
        fieldOrder.put(Integer.parseInt(jTextField9.getText()), "PLZ_ORT");
        fieldOrder.put(Integer.parseInt(jTextField10.getText()), "TEL");
        fieldOrder.put(Integer.parseInt(jTextField11.getText()), "FAX");
        fieldOrder.put(Integer.parseInt(jTextField12.getText()), "MOBIL");
        fieldOrder.put(Integer.parseInt(jTextField13.getText()), "MAIL1");
        fieldOrder.put(Integer.parseInt(jTextField14.getText()), "MAIL2");
        fieldOrder.put(Integer.parseInt(jTextField15.getText()), "GEBURTSTAG");
        fieldOrder.put(Integer.parseInt(jTextField16.getText()), "ABITUR");
        fieldOrder.put(Integer.parseInt(jTextField17.getText()), "AEMTER");
        fieldOrder.put(Integer.parseInt(jTextField18.getText()), "FIRMA");
        fieldOrder.put(Integer.parseInt(jTextField19.getText()), "RANG");
        fieldOrder.put(Integer.parseInt(jTextField20.getText()), "BERUF");
        fieldOrder.put(Integer.parseInt(jTextField21.getText()), "F_PLZ_ORT");
        fieldOrder.put(Integer.parseInt(jTextField22.getText()), "F_TEL");
        fieldOrder.put(Integer.parseInt(jTextField23.getText()), "F_FAX");
        fieldOrder.put(Integer.parseInt(jTextField24.getText()), "F_MAIL");
        fieldOrder.put(Integer.parseInt(jTextField25.getText()), "VEREIN");
        fieldOrder.put(Integer.parseInt(jTextField26.getText()), "ANREDE");
        fieldOrder.put(Integer.parseInt(jTextField27.getText()), "TAGFIELD");
        fieldOrder.put(Integer.parseInt(jTextField28.getText()), "F_ANSCHRIFT");
        fieldOrder.put(Integer.parseInt(jTextField29.getText()), "GEAENDERT");
        fieldOrder.put(Integer.parseInt(jTextField30.getText()), "HINZUGEFUEGT");
      }
      catch (NumberFormatException nfe)
      {
        JOptionPane.showMessageDialog(null, "Die Reihenfolge darf nur in Ganzzahlen eingegeben werden",
                "Fehler!", 1);
      }
      //fieldOrder.
      return fieldOrder;
    }

    private static void insertData(String[] lineData, TreeMap <Integer, String> fieldOrder,
            String fileEncoding) throws ArrayIndexOutOfBoundsException, SQLException, UnsupportedEncodingException
    {
      String fieldList = "";
      String valueList = "";
      String val = null; //da speichern wir den String umcodiert zwischen

      for (int i = 0; i<= fieldOrder.lastKey(); i++)
      {
        if (fieldOrder.containsKey(i))
        {
          fieldList += fieldOrder.get(i) + ", ";

          //sonst laufen wir in die Falle bei anderen Encodings als UTF8 (z.B. Windoof -> Cp1252)
          val = new String(lineData[i-1].getBytes(), fileEncoding);

          if (commonFunctions.stringIsEmpty(val))
            valueList += "null, ";
          else
            valueList += "'" + commonFunctions.sqlSichern(val) + "', ";
        }
      }
      
      fieldList = fieldList.substring(0, fieldList.length() - 2); // "; " wegstreichen
      valueList = valueList.substring(0, valueList.length() - 2); // "; " wegstreichen
      String insertSQL = "insert into stammdaten (" + fieldList + ")" + " values (" + valueList + ")";
      System.out.println(insertSQL);
      Statement stmt = Main.con.createStatement();
      stmt.executeUpdate(insertSQL);
      stmt.close();
      zeile ++;
    }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JCheckBox jCheckBox1;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel11;
  private javax.swing.JLabel jLabel12;
  private javax.swing.JLabel jLabel13;
  private javax.swing.JLabel jLabel14;
  private javax.swing.JLabel jLabel15;
  private javax.swing.JLabel jLabel16;
  private javax.swing.JLabel jLabel17;
  private javax.swing.JLabel jLabel18;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel20;
  private javax.swing.JLabel jLabel21;
  private javax.swing.JLabel jLabel22;
  private javax.swing.JLabel jLabel23;
  private javax.swing.JLabel jLabel24;
  private javax.swing.JLabel jLabel25;
  private javax.swing.JLabel jLabel26;
  private javax.swing.JLabel jLabel27;
  private javax.swing.JLabel jLabel28;
  private javax.swing.JLabel jLabel29;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel30;
  private javax.swing.JLabel jLabel31;
  private javax.swing.JLabel jLabel32;
  private javax.swing.JLabel jLabel33;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JTextField jTextField1;
  private javax.swing.JTextField jTextField10;
  private javax.swing.JTextField jTextField11;
  private javax.swing.JTextField jTextField12;
  private javax.swing.JTextField jTextField13;
  private javax.swing.JTextField jTextField14;
  private javax.swing.JTextField jTextField15;
  private javax.swing.JTextField jTextField16;
  private javax.swing.JTextField jTextField17;
  private javax.swing.JTextField jTextField18;
  private javax.swing.JTextField jTextField19;
  private javax.swing.JTextField jTextField2;
  private javax.swing.JTextField jTextField20;
  private javax.swing.JTextField jTextField21;
  private javax.swing.JTextField jTextField22;
  private javax.swing.JTextField jTextField23;
  private javax.swing.JTextField jTextField24;
  private javax.swing.JTextField jTextField25;
  private javax.swing.JTextField jTextField26;
  private javax.swing.JTextField jTextField27;
  private javax.swing.JTextField jTextField28;
  private javax.swing.JTextField jTextField29;
  private javax.swing.JTextField jTextField3;
  private javax.swing.JTextField jTextField30;
  private javax.swing.JTextField jTextField4;
  private javax.swing.JTextField jTextField5;
  private javax.swing.JTextField jTextField6;
  private javax.swing.JTextField jTextField7;
  private javax.swing.JTextField jTextField8;
  private javax.swing.JTextField jTextField9;
  // End of variables declaration//GEN-END:variables

}
